/*
ID: simplyz2
LANG: C
TASK: palsquare
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LEN 21 /* for 300^2 when base is 2 */
#define N 300
int bs, len, orilen;
char ret[MAX_LEN], ori[MAX_LEN];

void
transform(int base, int num, char *rt, int maxlen, int *rtlen)
{
	int i, mod;
	char ch;
	memset(rt, 0, sizeof(char)*maxlen);
	*rtlen = 0;
	while(num != 0) {
		mod = num % base;
		if(mod < 10)
			rt[*rtlen] = mod+'0';
		else
			rt[*rtlen] = mod-10+'A';
		++(*rtlen);
		num = num / base;
	}
	for(i=0; i<((*rtlen)/2); i++) {
		ch = rt[i];
		rt[i] = rt[(*rtlen)-i-1];
		rt[(*rtlen)-i-1] = ch;
	}
}

int
is_valid(char *str, int length)
{
	int i;
	for(i=0; i<length/2; i++)
		if(str[i] != str[length-i-1])
			return 0;
	return 1;
}

void
solve()
{
	int i, sq;
	for(i=1; i<=N; i++) {
		sq = i*i;
		transform(bs, sq, ret, MAX_LEN, &len);
		if(is_valid(ret, len)) {
			transform(bs, i, ori, MAX_LEN, &orilen);
			printf("%s %s\n", ori, ret);
		}
	}
}

int
main(int argc, char **argv)
{
	freopen("palsquare.in", "r", stdin);
	freopen("palsquare.out", "w", stdout);
	while(scanf("%d", &bs) != EOF) {
		solve();
	}
	return 0;
}
